package cc.permission.infrastructure.impl;

import cc.permission.domain.User;
import cc.permission.infrastructure.UserTunnel;
import cc.permission.infrastructure.tunnel.mysql.UserDto;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 描述:
 *
 * @author wangyan
 * @date 2020/4/2
 */
public class UserMysqlTunnel implements UserTunnel {
    @Override
    public void save(User user) {
        UserDto userDto = new UserDto();
        userDto.setVid(user.getUserId());
        userDto.setAppid(user.getAppId());
        userDto.setTenantid(user.getTenantId());
        userDto.setOrgid(user.getOrgId());
        userDto.insert();
    }

    /**
     * 修改用户
     *
     * @param user
     * @return
     * @author muxiaoxue
     */
    @Override
    public int update(User user) {
        UserDto userDto = new UserDto();
        userDto.setNid(user.getNid());
        userDto.setVid(user.getUserId());
        userDto.setAppid(user.getAppId());
        userDto.setTenantid(user.getTenantId());
        userDto.setOrgid(user.getOrgId());
        return userDto.update();
    }

    /**
     * 获取用户信息
     *
     * @param nid 主键nid
     * @return
     * @author muxiaoxue
     */
    @Override
    public User get(int nid) {
        UserDto userDto = UserDto.getOne(UserDto.class, nid);
        User user = new User();
        if (userDto != null) {
            user.setNid(userDto.getNid());
            user.setUserId(userDto.getVid());
            user.setTenantId(userDto.getTenantid());
            user.setAppId(userDto.getAppid());
            user.setOrgId(userDto.getOrgid());
        }
        return user;
    }

    @Override
    public List<User> query() {
        return null;
    }

    /**
     * 根据用户组ID返回用户集合
     * @param id
     * @return
     */
    @Override
    public List<User> queryByUserGroup(Integer id) {
        List<User> userList = new ArrayList<>();

        return userList;
    }

}
